package com.gitee.ly.chain.abstractclass;

import com.gitee.ly.chain.Flow;
import com.gitee.ly.chain.Link;

import java.util.List;
import java.util.UUID;

/**
 * AbstractFlow
 *
 * @author ly
 **/
public final class AbstractTemplateFlow implements Flow<Object> {
    private String type = null;
    private String name = null;

    private AbstractTemplateFlow() {
    }

    AbstractTemplateFlow(String type, String name) {
        this.type = type;
        this.name = name;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public List<Link> allLink() {
        return GlobalTool.getLinkListByFlowType(this.type);
    }

    @Override
    public void excute(Object data) {
        String uid = UUID.randomUUID().toString();
        for (Link link : allLink()) {
            if (link instanceof AbstractTemplateLink) {
                ((AbstractTemplateLink) link).excute(uid, data);
            }
        }
    }
}
